package com.newtouch.bxzs.business.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newtouch.bxzs.business.product.model.RecommendationSafeGuardInterestsMapBO;
import com.newtouch.bxzs.business.product.model.RecommendationSafeGuardInterestsMapSubBO;
import com.newtouch.bxzs.common.base.model.RecommendationSafeGuardInterestsFormulaMap;
import com.newtouch.bxzs.common.base.model.RecommendationSafeGuardInterestsMap;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 建议书保障的mapper类，必须继承BaseMapper
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/11 14:54</td>
 * <td>lanwei</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lanwei
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface RecommendationSafeGuardInsuranceMapMapper extends BaseMapper<RecommendationSafeGuardInterestsMap> {

    /**
     * 向建议书附加险保障关联表插入记录
     *
     * @param list RecommendationSafeGuardInsuranceMap集合
     */
    @Insert("<script>" +
            "INSERT INTO ASSISTANT_RECOMMENDATION_SAFEGUARD_INTERESTS_MAP \n" +
            "(RECOMMENDATION_SAFEGUARD_INTERESTS_MAP_ID,SAFEGUARD_INTERESTS_TITLE,SAFEGUARD_INTERESTS_CONTENT,SAFEGUARD_INTERESTS_SUBCONTENT,SAFEGUARD_INTERESTS_DETAILED_SUBCONTENT,RECOMMENDATION_ID,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME)\n" +
            "VALUES\n" +
            "\t<foreach collection='list' item='item' index='index' separator=','>\n" +
            "\t(replace(uuid(),'-',''),#{item.safeGuardInterestsTitle}, #{item.safeGuardInterestsContent},#{item.safeGuardInterestsSubContent},#{item.safeGuardInterestsDetailedSubContent}, #{item.recommendationId}, #{item.createUserId}, #{item.createTime}, #{item.updateUserId}, #{item.updateTime})" +
            "\t</foreach>" +
            "</script>")
    void insertIntoMapBach(@Param("list") List<RecommendationSafeGuardInterestsMap> list);

    /**
     * 根据建议书id查询名目集合
     * @param recommendationId 根据建议书id
     * @return 名目集合
     */
    @Select("SELECT\n" +
            "\ta.SAFEGUARD_INTERESTS_TITLE,\n" +
            "\ta.SAFEGUARD_INTERESTS_DETAILED_SUBCONTENT \n" +
            "FROM\n" +
            "\tASSISTANT_RECOMMENDATION_SAFEGUARD_INTERESTS_MAP AS a \n" +
            "WHERE\n" +
            "\ta.RECOMMENDATION_ID = #{recommendationId} \n" +
            "GROUP BY\n" +
            "\ta.SAFEGUARD_INTERESTS_TITLE,\n" +
            "\ta.SAFEGUARD_INTERESTS_DETAILED_SUBCONTENT")
    List<RecommendationSafeGuardInterestsMapBO> getSafeGuardInsuranceTitleList(@Param("recommendationId")String recommendationId);

    /**
     * 根据名目查询和建议书id查询子内容和内容的集合
     * @param recommendationId 建议书id
     * @param title 名目
     * @return 子内容和内容的集合
     */
    @Select("SELECT\n" +
            "\ta.SAFEGUARD_INTERESTS_CONTENT,\n" +
            "\ta.SAFEGUARD_INTERESTS_SUBCONTENT \n" +
            "FROM\n" +
            "\tASSISTANT_RECOMMENDATION_SAFEGUARD_INTERESTS_MAP AS a \n" +
            "WHERE\n" +
            "\ta.RECOMMENDATION_ID = #{recommendationId} \n" +
            "\tAND a.SAFEGUARD_INTERESTS_TITLE = #{title}")
    List<RecommendationSafeGuardInterestsMapSubBO> getSafeGuardInsuranceSubList(@Param("recommendationId")String recommendationId, @Param("title")String title);

    /**
     * 向建议书利益演示关联表插入记录
     *
     * @param list RecommendationSafeGuardInterestsFormulaMap集合
     */
    @Insert("<script>" +
            "INSERT INTO  ASSISTANT_RECOMMENDATION_SAFEGUARD_INTERESTS_FORMULA_MAP\n" +
            "(RECOMMENDATION_SAFEGUARD_INTERESTS_FORMULA_MAP_ID,SAFEGUARD_INTERESTS_TYPE,SAFEGUARD_INTERESTS_TYPE_NAME,SAFEGUARD_INTERESTS_SUBTYPE,SAFEGUARD_INTERESTS_SUBTYPE_NAME,SAFEGUARD_INTERESTS_SUBTYPE_FORMULA,SAFEGUARD_INTERESTS_SUBTYPE_INITIAL_VALUE,RECOMMENDATION_ID,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME)\n" +
            "VALUES\n" +
            "\t<foreach collection='list' item='item' index='index' separator=','>\n" +
            "\t(replace(uuid(),'-',''),#{item.safeGuardInterestsType}, #{item.safeGuardInterestsTypeName},#{item.safeGuardInterestsSubType},#{item.safeGuardInterestsSubTypeName},#{item.safeGuardInterestsSubTypeFormula}, #{item.safeGuardInterestsSubTypeInitialValue}, #{item.recommendationId}, #{item.createUserId}, #{item.createTime}, #{item.updateUserId}, #{item.updateTime})" +
            "\t</foreach>" +
            "</script>")
    void insertIntoFormulaMapBach(@Param("list") List<RecommendationSafeGuardInterestsFormulaMap> list);

}
